import Vue from 'vue'
import App from './App'
import store from './store'
import $AppEntryController from './AppEntryController.js'
import * as $apis from './apis/index.js'
import $mRouter from './common/router.js'
import $mUtils from './common/utils.js'
import $mConfig from "./config/index.config.js"
import $mAssetsPath from './config/assets.config.js'
import $mRoutesConfig from './config/routes.config.js'
import $mConstDataConfig from './config/constData.config.js'
import TriTree from '@/components/tki-tree/tki-tree.vue'
import TabbarView from "./common/TabBarView.js";
Vue.prototype.$tabbarView = new TabbarView();

// 引入全局uView
import uView from 'uview-ui'
Vue.use(uView)



Vue.component("TriTree",TriTree)
Vue.config.productionTip = false;

Vue.prototype.$AppEntryController = $AppEntryController;

Vue.prototype.$store = store;

Vue.prototype.$apis = $apis;

Vue.prototype.$mRouter = $mRouter;

Vue.prototype.$mUtils = $mUtils;

Vue.prototype.$mConfig = $mConfig;

Vue.prototype.$mAssetsPath = $mAssetsPath;

Vue.prototype.$mRoutesConfig = $mRoutesConfig;

Vue.prototype.$mConstDataConfig = $mConstDataConfig;

const currentVersion = {
	id: 1
}

// const prePage = () => {
// 	let pages = getCurrentPages();
// 	let prePage = pages[pages.length - 2];
// 	// #ifdef H5
// 	return prePage;
// 	// #endif
// 	// #ifdef APP-PLUS
// 	return prePage.$vm;	
// 	// #endif
// }
// Vue.prototype.$api = {
// 	prePage
// };

Vue.prototype.$current = currentVersion

$mRouter.beforeEach((navType, to) => {
	if (to.route === undefined) throw ("路由钩子函数中没有找到to.route对象，路由信息:" + JSON.stringify(to));

	if (to.route.path === $mRoutesConfig.login.path && store.getters.hasLogin) {
		uni.switchTab({
			url: $mUtils.objParseUrlAndParam($mRoutesConfig.login.path, to.query)
		})
		return;
	}

	// 过滤需要权限的页面
	if (to.route.requiresAuth) {

		if (store.getters.hasLogin) {
			// 已经登录
			uni[navType]({
				url: $mUtils.objParseUrlAndParam(to.route.path, to.query)
			})
		} else {
			// 登录成功后的重定向地址和参数
			let query = {
				redirectUrl: to.route.path,
				...to.query
			}
			// 没有登录 是否强制登录?
			if (store.state.forcedLogin) {
				uni.redirectTo({
					url: $mUtils.objParseUrlAndParam($mRoutesConfig.login.path, query)
				})
			} else {
				uni.navigateTo({
					url: $mUtils.objParseUrlAndParam($mRoutesConfig.login.path, query)
				})
			}
		}
	} else {
		uni[navType]({
			url: $mUtils.objParseUrlAndParam(to.route.path, to.query)
		})
	}
})
Vue.prototype.shareList = [{
		icon: $mAssetsPath.wx_share,
		text: "微信好友",
	},
	{
		icon: $mAssetsPath.pyq_share,
		text: "朋友圈"
	},
	{
		icon: $mAssetsPath.qq_share,
		text: "QQ"
	},
	{
		icon: $mAssetsPath.weibo_share,
		text: "微博"
	}
];
Vue.prototype.format_je = (data) => {
	if (!data) return 0.00;
	if (data.toFixed) return data.toFixed(2);
	else return data;

};
App.mpType = 'app'

const app = new Vue({
	store,
	...App
})
app.$mount()
